package com.study.SellTicket2;

public class Windows extends Thread{
    private String name;
    public Windows(String name){
        this.name = name;
    }

    @Override
    public void run() {
        this.sell();
    }
    public void sell(){
        while (Ticket.number>0){
            synchronized (Windows.class){
                try {
                    if(Ticket.number >0){
                        Ticket.number--;
                        System.out.println(name+"卖出一张票，余票："+Ticket.number);
                        Thread.sleep(200);
                    }
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
